package main

import (
	"fmt"
	"time"

	"boomlive.com/boomlive-common/configs"
	"boomlive.com/boomlive-common/utils"
	"boomlive.com/boomlive-openapi-game/controllers"
	_ "boomlive.com/boomlive-openapi-game/routers"
	"github.com/beego/beego/v2/core/logs"
	beego "github.com/beego/beego/v2/server/web"
)

func main() {
	err := configs.ConfigInit()
	if err != nil {
		fmt.Println(time.Now().Format("2006-01-02 15:04:05") + " ConfigInit fail, exiting main, " + err.Error())
		return
	}

	utils.SetLogConfig()

	logs.Info("HttpPortBoomliveOpenapiGame:", configs.HttpPortBoomliveOpenapiGame)

	logs.Info("BEEGO_PRODUCT=" + configs.ProductName)
	logs.Info("BEEGO_ENV=" + configs.EnvName)
	logs.Info("BEEGO_RUNMODE=" + configs.RunMode)

	//utils.RedisInit()
	//utils.DbInit()
	utils.GetDBORM()
	beego.ErrorController(&controllers.ErrorController{})

	// 启动所有定时程序
	//utils.RunTasksWithWg() // 需要时打开, 配置在routers/task.go
	// 启动所有mq消费程序
	// utils.RunListenersWithWg() // 需要时打开, 配置在routers/listener.go
	// 启动http服务
	utils.RunHttpServerWithWg(configs.HttpPortBoomliveOpenapiGame) // 需要时打开, 配置在routers/router.go

	// 保持服务运行, 防止主线程退出
	utils.ServerRunWg.Wait() // tasks所有定时任务return, http服务终止, mq所有消费者首次listen返回失败

	logs.Info("ServerRunWg.Wait() return, exiting main")
}
